/**
 * <p>Copyright (c) 2017 深圳市鹏途交通科技有限公司 </p>
 * <p>				   All right reserved. 		     </p>
 * 
 * <p>项目名称 ： 	深圳市国省检日常化监管系统         </p>
 * <p>创建者   :	hey 
 * 
 * <p>描   述  :   TunnelRecordController.java for com.pengtu.gsj.controller.yh    </p>
 * 
 * <p>最后修改 : $: Sep 18, 2017-2:10:36 PM v 1.0.0	 hey   $ </p>
 * 
*/

package com.pengtu.gsj.controller.yh;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pengtu.gsj.controller.base.DefaultBaseController;
import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.entity.yh.TunnelRecord;
import com.pengtu.gsj.interceptor.Token;
import com.pengtu.gsj.service.yh.TunnelRecordService;
import com.pengtu.gsj.utils.MathsUtils;
import com.pengtu.gsj.utils.web.SpringMvcUtils;

/**
 * 
 * TunnelRecordController
 * 
 * Sep 18, 2017 2:10:36 PM
 * 
 * @version 1.0.0
 * 
 */
@Controller
@RequestMapping("tunnelRecord")
public class TunnelRecordController extends DefaultBaseController{
	@Autowired
	private TunnelRecordService tunnelRecordService;
	
	
	
	/**
	 * 加载
	 * @param id
	 * @return
	 */
	@ModelAttribute
	public TunnelRecord load(String id){
		TunnelRecord tunnelRecord;
		if(StringUtils.isNotEmpty(id)){
			tunnelRecord = tunnelRecordService.getTunnelRecordById(id);
		}else{
			tunnelRecord = new TunnelRecord();
		}
		return tunnelRecord;
	}
	
	
	/**
	 * 页面跳转
	 * @return
	 */
	@Token(save = true)
	@RequestMapping("listInfo")
	public String showLisfInfo() {
		return "yh/tunnelRecord_list";
	}
	
	
	/**
	 * 
	 * getRoadMaterialList:
	 * 适用:
	 * @param page
	 * @param request
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	@ResponseBody
	@RequestMapping(value="list", produces = "application/json; charset=utf-8")
	public Page<TunnelRecord> getRoadMaterialList(Page<TunnelRecord> page, HttpServletRequest request){
		QueryFilter queryFilter = QueryFilter.buildFromHttpRequest(request);
		if (!page.isOrderBySetted()) {
			page.setOrderBy("testYear");
			page.setOrder(Page.ASC);
		}
		page = tunnelRecordService.findTunnelRecord(page,queryFilter);
		return page;
	}
	
	/**
	 * 保存
	 * @param roadMaterial
	 * @return
	 */
	@ResponseBody
	@Token(remove = true)
	@RequestMapping(value = "save", method=RequestMethod.POST)
	public boolean saveTunnelRecord(@ModelAttribute TunnelRecord tunnelRecord){
		tunnelRecord.setGovernPate(MathsUtils.divDouble((tunnelRecord.getCheckTunnel() - tunnelRecord.getGovernTunnel())*100, tunnelRecord.getCheckTunnel(), 2));
		tunnelRecordService.saveTunnelRecord(tunnelRecord);
		return true;
	}
	
	
	/**
	 * 加载数据
	 * @param infoManagement
	 * @return
	 */
	@ResponseBody  
	@RequestMapping(value="show")
	public TunnelRecord showTunnelRecord (@ModelAttribute TunnelRecord tunnelRecord){
		return tunnelRecord;
	}
	
	/**
	 * 删除
	 * @param infoManagement
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="delete")
	public boolean delateInfoManagement(@ModelAttribute TunnelRecord tunnelRecord){
		tunnelRecordService.delateTunnelRecord(tunnelRecord);
		return true;
	}
	
	@ResponseBody
	@RequestMapping("checkTestYear")
	public boolean checkTestYear(){
		String testYear = SpringMvcUtils.getParameter("testYear");
		String id = SpringMvcUtils.getParameter("id");
		return tunnelRecordService.checkTestYear(testYear, id);
	}
}
